<?php

class Aset_model extends Model {
	
	var $data;

	function Aset_model()
	{
		parent::Model();
	}
	
	function get_all_data(){
		$query = $this->db->query('select * from aset');
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_jum_data(){
		$query = $this->db->query('select count(*) as jumlah from aset');
		if ($query->num_rows() > 0)
		{
			return $query->row();
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_last_id(){
		$query = $this->db->query('select * from aset order by id_aset desc limit 1 ');
		if ($query->num_rows() > 0)
		{
			return $query->row();
		}
		else
		{
			return FALSE;
		}
	}

	function get_data_by_id($id){
		$this->db->where('id', $id);
		$query = $this->db->get('aset');
		if ($query->num_rows() > 0)
		{
			return $query->row_array();
		}
		else
		{
			return FALSE;
		}
	}

	function fill_data()
	{
		$this->data = array(
			'id_aset' => $this->input->post('id_aset'),
			'nama_aset' => $this->input->post('nama_aset'),			
			'nilai_residu' => $this->input->post('nilai_residu'),
			'ktp' => $this->input->post('ktp'),
			'sim' => $this->input->post('sim'),
			'tempat_lahir' => $this->input->post('tempat_lahir'),
			'tgl_beli' => $this->input->post('tgl_beli'),
			'tgl_hitung' => $this->input->post('tgl_hitung'),
			'harga_beli' => $this->input->post('harga_beli'),
			'nilai_buku' => $this->input->post('nilai_buku'),
			'telpon_2' => $this->input->post('handphone'),
			'keterangan' => $this->input->post('keterangan')
		);
	}
	
	//Check for duplicate ID aset
	function check_name($id = '')
	{
		$this->db->where('id_aset', $this->data['id_aset']);
		if($id != '') $this->db->where('id !=', $id);
		$query = $this->db->get('aset');

		if ($query->num_rows() > 0)
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}	

	function insert_data()
	{
		$insert = $this->db->insert('aset', $this->data);
		return $insert;
	}

	function update_data($id)
	{
		$this->db->where('id', $id);
		$update = $this->db->update('aset', $this->data);
		return $update;
	}

	function delete_data($id){
		$this->db->where('id', $id);
		$delete = $this->db->delete('aset');
		return $delete;
	}

}

/* End of file aset_model.php */
/* Location: ./application/models/aset_model.php */
